package com.yycx.module.bus.provider.controller.hy;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.utils.DateUtils;
import com.yycx.module.system.client.entity.SysCompany;
import com.yycx.module.system.provider.service.SysCompanyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yycx.common.mybatis.model.*;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.hy.BusHyorderInovice;
import com.yycx.module.bus.provider.service.hy.BusHyorderInoviceService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 结算发票控制器
 *
 * @author flyme
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/bus/bhi/")
public class BusHyorderInoviceController extends BaseController<BusHyorderInoviceService, BusHyorderInovice>  {

    @Autowired
    private SysCompanyService companyService;

    @ApiOperation(value = "结算发票-分页列表", notes = "结算发票分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "结算发票-列表", notes = "结算发票列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "结算发票-添加", notes = "添加结算发票")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "结算发票-更新", notes = "更新结算发票")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "结算发票-删除", notes = "删除结算发票")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "结算发票-详情", notes = "结算发票详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    /**
     * 导出数据
     *
     * @param params
     * @param request
     * @param response
     */
    @PostMapping(value = "export")
    public void export(@RequestParam(required = false) Map params, HttpServletRequest request, HttpServletResponse response) {
        long date = DateUtils.getCurrentTimestamp();
        String handlerName = MapUtil.getStr(params, "handlerName");
        Long companyId = OpenHelper.getCompanyId();
        SysCompany company = companyService.getById(companyId);
        String fileName = company.getCompanyName() + "-" + MapUtil.getStr(params, "fileName");
        bizService.export(params, request, response, fileName + DateUtil.formatDate(DateUtil.date()), fileName, handlerName);
    }

}
